<?php

namespace app\admin\controller\check;

use app\admin\model\Lift;
use app\admin\model\User;
use app\common\controller\Backend;
use app\common\library\Auth;
use think\Db;

/**
 * 清洁审核管理
 *
 * @icon fa fa-user
 */
class Order extends Backend
{

    protected $relationSearch = true;
    protected $searchFields = 'id,username,nickname';
    protected $noNeedRight = ['getPackage', 'getDuration', 'getspecifications', 'getClassRoom', 'getTeacher', 'getSchoolClass'];

    /**
     * @var \app\admin\model\User
     */
    protected $model = null;
    protected $service_model = null;
    protected $sale_model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('check.Order');
        $this->service_model = model('Service');
        $this->sale_model = model('OrderServiceSales');
    }

    /**
     * 查看
     */
    public function index()
    {
        $this->relationSearch = true;
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            $new_where = [
             //   'free_clean_id' => 0,
             //   'lift_id' => ['>', 0],
                'order.is_del' => 0,
                'order.id' => ['>',103]
            ];
            $where = [];
            $filter = $this->request->get('filter');
            $offset = $this->request->get('offset');
            $order = $this->request->get('order');
            $sort = $this->request->get('sort');
            $limit = $this->request->get('limit');
            $filter = json_decode($filter,true);
            $string = '';
            foreach ($filter as $w=>$v){
               // var_dump($w);
                if($w=='add_time'){
                    $time_arr = explode(' - ',$v);
                    $where['order.add_time'] = ['between',[strtotime($time_arr[0]),strtotime($time_arr[1])]];
                    //  $where_new['end_time'] = ['<=',$time_arr[1]];
                }else if($w=='uid'   || $w=='package' || $w=='duration' || $w=='clean_area'){
                    $where[$w] = $v;
                }else if($w=='lift.lift_number' || $w=='order_id' || $w=='lift.real_name' || $w=='lift.phone' || $w=='lift.buildings'){
                    $where[$w] = ['like','%'.$v.'%'];
                }else if($w=='province' || $w=='city' || $w=='area'){
                    $string.= $v.'-';
                }else if($w=='status'){
                    if($v== '-1'){
                        $where['order.status'] = ['in',[-1,-2]];
                    }else{
                        $where['order.status'] = $v;
                    }
                } else if ($w == 'lifts.lift_number') {
                    $where['lift.lift_number | free.elevator_no'] = ['like', '%' . $v . '%'];
                } else if ($w == 'lifts.real_name') {
                    $where['lift.real_name | free.proprietor_name'] = ['like', '%' . $v . '%'];
                } else if ($w == 'lifts.phone') {
                    $where['lift.phone | free.phone'] = ['like', '%' . $v . '%'];
                } else if ($w == 'lifts.specific_address') {
                    $where['lift.specific_address | free.specific_address'] = ['like', '%' . $v . '%'];
                } else if ($w == 'lifts.specifications_name') {
                    $where['specifications'] = $v;
                } else if ($w == 'personnel_id') {
                    $where['order.personnel_id'] = $v;
                }
            }
            if($string){
                $string = substr($string, 0, -1);
                $where['lift.area | free.address '] = $string;
            }
            $count = $this->model
//                ->with(['user', 'spread', 'refund', 'sales', 'lift','service'])
                ->with(['lift','free'])
                ->where($where)
                ->where($new_where)
                ->count();
            $list = $this->model
//                ->with(['user', 'spread', 'refund', 'sales', 'lift','service'])
                ->with(['lift','free'])
                ->where($where)
                ->where($new_where)
                ->order('order.add_time DESC,order.id DESC')
                ->field('order.*,lift.*,order.id as id,order.status as status,order.add_time as add_time,order.personnel_id as personnel_id')
                ->limit($offset, $limit)
                ->select();
            
            foreach ($list as $w => &$v) {
                //判断specific_address字段里是否有梯和栋字有的话不加 没有的话加上
                if (strpos($v['lift']['specific_address'], '梯') == false) {
                    $v['lift']['specific_address'] = $v['lift']['specific_address'] . $v['lift']['building'] . '栋' . $v['lift']['unit'] . '梯';
                }
                if ($v['free_clean_id'] > 0) {
                    $elevator_no = Db::name('free_clean')->where(['id' => $v['free_clean_id']])->find();
                    $v['lifts'] = [
                        'lift_number' => $elevator_no['elevator_no'],
                        'area' => $elevator_no['address'],
                        'buildings' => $elevator_no['buildings'],
                        'real_name' => $elevator_no['proprietor_name'],
                        'phone' => $elevator_no['phone'],
                        'specific_address' => $elevator_no['buildings'],
                    ];
                    //   var_dump($v['lift']);
                } else {
                    $v['lifts'] = $v['lift'];
                }
                if ($v['personnel_id']) {
                    $v['personnel'] = Db::name('user')->where(['uid'=>$v['personnel_id']])->value('real_name');
                }
            }
            $sql = Db::name('store_order')->getLastSql();
            $result = array("total" => $count, "rows" => $list, 'sql' => $sql);

            return json($result);
        }
        return $this->view->fetch();
    }

    /**
     * 添加
     */
    public function add()
    {
        if ($this->request->isPost()) {
            $params = $this->request->post("row/a");
            $params['create_time'] = time();
            $params['admin_id'] = $this->auth->id;
            $image_arr = explode('aliyuncs.com', $params['logo']);
            if ($params['logo']) {
                $params['logo'] = $image_arr[1];
            }
            $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
            $randStr = str_shuffle($str);
            $rands = substr($randStr, 0, 6);
            $params['code'] = $rands;
            $res = $this->model->insert($params);
            if ($res) {
                $this->success();
            }
            $this->error();
        }
        return $this->view->fetch();
    }

    /**
     * 编辑
     */
    public function edit($ids = '')
    {
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        if ($this->request->isPost()) {
            $params = $this->request->post("row/a");
            if ($params) {
                try {
                    $params['update_time'] = time();
                    $params['admin_id'] = $this->auth->id;
                    $image_arr = explode('aliyuncs.com', $params['logo']);
                    if ($params['logo']) {
                        $params['logo'] = $image_arr[1];
                    }
                    $result = $row->allowField(true)->save($params);
                    if ($result !== false) {
                        $this->success();
                    } else {
                        $this->error($row->getError());
                    }
                } catch (\think\exception\PDOException $e) {
                    $this->error($e->getMessage());
                } catch (\think\Exception $e) {
                    $this->error($e->getMessage());
                }
            }
            $this->error(__('Parameter %s can not be empty', ''));
        }
        if ($row['logo']) {
            $row['logo'] = 'https://yunwotuojiao.oss-cn-fuzhou.aliyuncs.com' . $row['logo'];
        }

        $this->view->assign("row", $row);
        return $this->view->fetch();
    }

    /**
     * 删除
     */
    public function del($ids = "")
    {
        if (!$this->request->isPost()) {
            $this->error(__("Invalid parameters"));
        }
        $ids = $ids ? $ids : $this->request->post("ids");
        $row = $this->model->get($ids);
        $this->modelValidate = true;
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        $this->model->where(['id' => $row['id']])->delete();
        $this->success();
    }

    /**
     * 详情
     */
    public function detail($ids = '')
    {
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        if ($this->request->isPost()) {
            $params = $this->request->post("row/a");
            if ($params) {
                try {
                    $params['update_time'] = time();
                    $params['admin_id'] = $this->auth->id;
                    $image_arr = explode('aliyuncs.com', $params['logo']);
                    if ($params['logo']) {
                        $params['logo'] = $image_arr[1];
                    }
                    $result = $row->allowField(true)->save($params);
                    if ($result !== false) {
                        $this->success();
                    } else {
                        $this->error($row->getError());
                    }
                } catch (\think\exception\PDOException $e) {
                    $this->error($e->getMessage());
                } catch (\think\Exception $e) {
                    $this->error($e->getMessage());
                }
            }
            $this->error(__('Parameter %s can not be empty', ''));
        }
        if ($row['complete_time'] > 0) {
            $row['complete_time'] = date('Y-m-d H:i:s', $row['complete_time']);
        } else {
            $row['complete_time'] = '-';
        }
        if ($row['pay_time'] > 0) {
            $row['pay_time'] = date('Y-m-d H:i:s', $row['pay_time']);
        } else {
            $row['pay_time'] = '-';
        }
        if ($row['add_time'] > 0) {
            $row['add_time'] = date('Y-m-d H:i:s', $row['add_time']);
        }

        $row['goods_img'] = '';
        //  var_dump($row);
        if ($row['free_clean_id'] > 0) {
            $elevator_no = Db::name('free_clean')->where(['id' => $row['free_clean_id']])->find();
            $row['lift'] = [
                'lift_number' => $elevator_no['elevator_no'],
                'area' => $elevator_no['address'],
                'buildings' => $elevator_no['buildings'],
                'real_name' => $elevator_no['proprietor_name'],
                'phone' => $elevator_no['phone'],

            ];
        }else{
            $row['lift'] = Db::name('lift')->where(['id' => $row['lift_id']])->find();
        }

        $sku_info = Db::name('store_product_attr_value')->where(['unique' => $row['product_unique']])->field('product_id,image')->find();
        $row['total_service_num'] = Db::name('store_order_service')->where(['order_id' => $row['order_id']])->count();
        $row['discount_amount'] = $row['total_price'] - $row['pay_price'];
        if ($sku_info) {
            $product_info = Db::name('store_product')->where(['id' => $sku_info['product_id']])->field('image,id')->find();
            $row['goods_img'] = $sku_info['image'];
        }
        if ($row['personnel_id']) {
            $row['user'] = Db::name('user')->where(['uid'=>$row['personnel_id']])->find();

        }else{
            $json['real_name'] = '暂无';
            $row['user'] = $json;
        }
        $this->view->assign("row", $row);
        return $this->view->fetch();
    }


    /**
     * 申请延期
     */
    public function postpone($ids = '')
    {
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        if ($this->request->isPost()) {
            $params = $this->request->post("row/a");
            if ($params) {
                try {
                    if (!$params['order_id']) {
                        $this->error('参数有误');
                    }
                    if (!$params['delay_time']) {
                        $this->error('请选择延期时间');
                    }
                    if (!$params['reason_delay']) {
                        $this->error('请填写延期原因');
                    }
                    if (!$params['reason_moth']) {
                        $this->error('请选择延期时长');
                    }
                    $order = $this->model->where(['order_id' => $params['order_id']])->find();
                    if ((int)$order['reason_moth'] + (int)$params['reason_moth'] > 12) {
                        $this->error('延期时长不能超过12个月');
                    }
                    $where = [
                        'order_id' => $params['order_id'],
                        'service_time' => ['>', strtotime($params['delay_time'])],
                        'status' => 1,
                    ];
                    $service_info = $this->service_model->where($where)->select();
                    if (!$service_info) {
                        $this->error('没有可延期的订单');
                    }
                    $where = [
                        'order_id' => $params['order_id'],
                        'service_time' => ['between', [strtotime($params['delay_time']), (strtotime($params['delay_time'])) + (86400 * 2)]],
                        'status' => 1,
                    ];
                    $old_service = $this->service_model->where($where)->select();
                    if (!$old_service) {
                        $this->error('延期时间两天内有清洁订单，不能延期');
                    }
                    foreach ($service_info as &$v) {
                        $reason_moth = $params['reason_moth'];
                        //服务时间增加【延期时长】月
                        if (!empty($v['moth_first_service'])) {
                            $array['moth_first_service'] = strtotime("+" . $reason_moth . " month", $v['moth_first_service']);
                        }
                        if (!empty($v['moth_end_service'])) {
                            $array['moth_end_service'] = strtotime("+" . $reason_moth . " month", $v['moth_end_service']);
                        }
                        if (!empty($v['first_service'])) {
                            $array['first_service'] = strtotime("+" . $reason_moth . " month", $v['first_service']);
                        }
                        if (!empty($v['end_service'])) {
                            $array['end_service'] = strtotime("+" . $reason_moth . " month", $v['end_service']);
                        }
                        if (!empty($v['service_time'])) {
                            $array['service_time'] = strtotime("+" . $reason_moth . " month", strtotime($v['service_time']));
                        };
                        //用file写入日志
                        $array['reason_delay'] = $params['reason_delay'];
                        $array['reason_moth'] = (int)$v['reason_moth'] + (int)$params['reason_moth'];
                        $array['year'] = date('Y', $array['service_time']);
                        $array['moth'] = date('m', $array['service_time']);
                        $array['delay_time'] = $params['delay_time'];
                        $this->service_model->where(['id' => $v['id']])->update($array);
                    }
                    $data['reason_moth'] = (int)$order['reason_moth'] + (int)$params['reason_moth'];
                    $true = $this->model->where(['order_id' => $params['order_id']])->update($data);
                    if ($true) {
                        $this->success('延期成功');
                    } else {
                        $this->error('延期失败');
                    }
                } catch (\think\exception\PDOException $e) {
                    $this->error($e->getMessage());
                } catch (\think\Exception $e) {
                    $this->error($e->getMessage());
                }
            }
            $this->error(__('Parameter %s can not be empty', ''));
        }
        $this->view->assign("row", $row);

        return $this->view->fetch();
    }

    /**
     * 详情
     */
    public function do_assign($ids = '')
    {
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        if ($this->request->isPost()) {
            $params = $this->request->post("row/a");
            if ($params) {
                try {
                    $params['up_time'] = time();
                    $result = $row->allowField(true)->save($params);
                    if ($result !== false) {
                        $this->success();
                    } else {
                        $this->error($row->getError());
                    }
                } catch (\think\exception\PDOException $e) {
                    $this->error($e->getMessage());
                } catch (\think\Exception $e) {
                    $this->error($e->getMessage());
                }
            }
            $this->error(__('Parameter %s can not be empty', ''));
        }
        //获取详情信息
        $row['is_have_saleman'] = 0;
        if ($row['personnel_id'] > 0) {
            $row['is_have_saleman'] = 1;
        }
        $row['salesman'] = Db::name('user')->where(['uid' => $row['personnel_id']])->value('real_name');
        $this->view->assign("row", $row);
        $this->assignconfig("is_have_saleman", $row['is_have_saleman']);
        return $this->view->fetch();
    }


    /**
     * 查看服务单
     */
    public function see_service_order($ids = '')
    {
        // var_dump($ids);
        if(!$ids) {
            $ids = $this->request->request('id');
        }
        $order_info = Db::name('store_order')
            ->alias('order')
            ->join('lift l', 'l.id=order.lift_id', 'left')
            ->where(['order.id' => (int)$ids])
            ->field('order.*,l.*,order.personnel_id as personnel_id,order.id as id')
            ->find();
        $status_name = $this->model->get_status_name();
        $order_info['status_text'] = $status_name[$order_info['status']];
        $sku_info = Db::name('store_product_attr_value')->where(['unique'=>$order_info['product_unique']])->find();
        $order_info['clean_area'] = $sku_info['disk_info'];
        $order_info['total_service_num'] = Db::name('store_order_service')->where(['order_id' => $order_info['order_id']])->count();
//        var_dump($order_info['order_id']);
//       // echo $this->model->getLastSql();
//        if (!$order_info) {
//            $this->error(__('No Results were found'));
//        }
        $this->relationSearch = true;
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            $order_id = $this->request->request('order_id');
            //  var_dump($order_id);
            $new_where = [
                'order_id' => $order_id,
                //  'lift_id'=>['>',0],
                //  'order.is_del'=>0
            ];
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            //   if ($where['status'] == 1) $where = $where + ['shipping_type' => 1];
            $count = $this->service_model->with(['lift'])
                //       ->with(['user', 'spread', 'refund', 'sales', 'lift','service'])
                //->where($where)
                ->where($new_where)
                ->count();
            $list = $this->service_model->with(['lift'])
                //   ->with(['user', 'spread', 'refund', 'sales', 'lift','service'])
                //  ->where($where)
                ->where($new_where)
                ->order('add_time DESC,id DESC')
                ->limit($offset, $limit)
                ->select();

            foreach ($list as &$v) {
                //判断specific_address字段里是否有梯和栋字有的话不加 没有的话加上
                if (strpos($v['lift']['specific_address'], '梯') == false) {
                    $v['lift']['specific_address'] = $v['lift']['specific_address'] . $v['lift']['building'] . '栋' . $v['lift']['unit'] . '梯';
                }
                if ($v['service_time'] > 0) {
                    $v['service_time'] = date('Y-m-d H:i:s', $v['service_time']);
                }
            }
            $sql = $this->model->getLastSql();
            $result = array("total" => $count, "rows" => $list, 'sql' => $sql);

            return json($result);
        }
        if ($order_info['complete_time'] > 0) {
            $order_info['complete_time'] = date('Y-m-d H:i:s', $order_info['complete_time']);
        } else {
            $order_info['complete_time'] = '-';
        }
        if ($order_info['pay_time'] > 0) {
            $order_info['pay_time'] = date('Y-m-d H:i:s', $order_info['pay_time']);
        } else {
            $order_info['pay_time'] = '-';
        }
        if ($order_info['add_time'] > 0) {
            $order_info['add_time'] = date('Y-m-d H:i:s', $order_info['add_time']);
        }
        $order_info['personnel'] = Db::name('user')->where(['uid'=>$order_info['personnel_id']])->value('real_name');
        $this->view->assign('row', $order_info);
        return $this->view->fetch();
    }

    /**
     * 服务单订单详情
     */
    public function service_detail($ids = '')
    {
        if(!$ids) {
            $ids = $this->request->request('id');
        }
        $row = $this->sale_model->alias('s')
            ->join('eb_store_order_service os','os.service_id = s.service_id','left')
            ->join('lift l','os.lift_id = l.id','left')
            ->join('store_order o','o.id = os.order_id','left')
            ->where(['os.id'=>$ids])
            ->order('s.add_time desc')
            ->field('s.*,l.*,l.real_name as l_real_name,l.id as l_id,o.*,os.*,o.id as o_id,os.id as os_id,s.id as id,s.number as number')
            ->find();
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        if ($this->request->isPost()) {
            $params = $this->request->post("row/a");
            if ($params) {
                try {
                    $params['update_time'] = time();
                    $params['admin_id'] = $this->auth->id;
                    $image_arr = explode('aliyuncs.com', $params['logo']);
                    if ($params['logo']) {
                        $params['logo'] = $image_arr[1];
                    }
                    $result = $row->allowField(true)->save($params);
                    if ($result !== false) {
                        $this->success();
                    } else {
                        $this->error($row->getError());
                    }
                } catch (\think\exception\PDOException $e) {
                    $this->error($e->getMessage());
                } catch (\think\Exception $e) {
                    $this->error($e->getMessage());
                }
            }
            $this->error(__('Parameter %s can not be empty', ''));
        }
        if($row['add_time'] >0){
            $row['add_time'] = date('Y-m-d H:i:s',$row['add_time']);
        }
        $row['service'] = Db::name('store_order_service')->where(['service_id'=>$row['service_id']])->find();
        $row['lift'] = Db::name('lift')->where(['id'=>$row['lift_id']])->find();
        if($row['remark'] ==1){
            $row['remark_text'] = '电梯损坏';
        }else if($row['remark'] ==2){
            $row['remark_text'] = '保洁员态度恶劣';
        }else{
            $row['remark_text'] = '其他';
        }
        if($row['pay_time'] >0){
            $row['pay_time'] = date('Y-m-d H:i:s',$row['pay_time']);
        }
        if($row['cleaning_end_time'] >0){
            $row['cleaning_end_time'] = date('Y-m-d H:i:s',$row['cleaning_end_time']);
        }
        if($row['service_time'] >0){
            $row['service_time'] = date('Y-m-d H:i:s',$row['service_time']);
        }
        if ($row['personnel_id']) {
            $row['user'] = Db::name('user')->where(['uid'=>$row['personnel_id']])->find();

        }else{
            $json['real_name'] = '暂无';
            $row['user'] = $json;
        }
        $row['personnel_name'] = User::where(['uid' => $row['personnel_id']])->value('real_name');
        $this->view->assign("row", $row);
        return $this->view->fetch();
        return $this->view->fetch();
    }

    /**
     * 申请售后
     */
    public function service_after_sale($ids = '')
    {
        $row = $this->service_model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        if ($this->request->isPost()) {
            $params = $this->request->post("row/a");
            if ($params) {
                try {
                    $result = true;
                    $re_info = Db::name('order_service_sales')->where(['service_id' => $row['service_id']])->find();
                    if (!$re_info) {
                        $sale_data = [
                            'service_id' => $row['service_id'],
                            'remark' => $row['remark'],
                            'uid' => $row['uid'],
                            'question' => $params['question'],
                            'image' => $params['image'],
                            'add_time' => time(),
                        ];
                        $result = Db::name('order_service_sales')->insert($sale_data);
                    }
                    if ($result !== false) {
                        $this->success();
                    } else {
                        $this->error($row->getError());
                    }
                } catch (\think\exception\PDOException $e) {
                    $this->error($e->getMessage());
                } catch (\think\Exception $e) {
                    $this->error($e->getMessage());
                }
            }
            $this->error(__('Parameter %s can not be empty', ''));
        }
        //获取详情信息
//        $row['is_have_saleman'] = 0;
//        if($row['personnel_id']>0){
//            $row['is_have_saleman'] = 1;
//        }
//        $row['salesman'] = Db::name('user')->where(['uid'=>$row['personnel_id']])->value('real_name');
        $this->view->assign("row", $row);
        //  $this->assignconfig("is_have_saleman", $row['is_have_saleman']);
        return $this->view->fetch();
    }


    /**
     * 申请售后
     */
    public function after_sale($ids = '')
    {
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        if ($this->request->isPost()) {
            $params = $this->request->post("row/a");
            if ($params) {
                try {
                    $result = true;
                    $re_info = Db::name('store_order_refund')->where(['order_id' => $row['order_id']])->find();
                    if (!$re_info) {
                        $sale_data = [
                            'store_order_id' => $row['id'],
                            'order_id' => $row['order_id'],
                            'uid' => $row['uid'],
                            'refund_reason' => $params['refund_reason'],
                            'refund_explain' => $params['refund_explain'],
                            'refund_img' => $params['refund_img'],
                            'add_time' => time(),
                        ];
                        $result = Db::name('store_order_refund')->insert($sale_data);
                    }

                    if ($result !== false) {
                        $this->success();
                    } else {
                        $this->error($row->getError());
                    }
                } catch (\think\exception\PDOException $e) {
                    $this->error($e->getMessage());
                } catch (\think\Exception $e) {
                    $this->error($e->getMessage());
                }
            }
            $this->error(__('Parameter %s can not be empty', ''));
        }
        //获取详情信息
//        $row['is_have_saleman'] = 0;
//        if($row['personnel_id']>0){
//            $row['is_have_saleman'] = 1;
//        }
//        $row['salesman'] = Db::name('user')->where(['uid'=>$row['personnel_id']])->value('real_name');
        $this->view->assign("row", $row);
        //  $this->assignconfig("is_have_saleman", $row['is_have_saleman']);
        return $this->view->fetch();
    }

    /**
     * 详情
     */
    public function do_most_assign($ids = '')
    {
//        $row = $this->model->get($ids);
//        if (!$row) {
//            $this->error(__('No Results were found'));
//        }
        if ($this->request->isPost()) {
            $params = $this->request->post("row/a");
            $check_id = $this->request->get("check_id");
            if ($params) {
                try {
                    $check_id_arr = explode(',', $check_id);
                    if (count($check_id_arr) == 0) {
                        $this->error('尚未选择任何一笔订单');
                    }
                    // $params['personnel'] = Db::name('user')->where(['uid'=>$params['personnel_id']])->value('real_name');
                    // $params['up_time'] = time();
                    // $params['salesman_id'] = time();
                    $result = $this->model->where(['id' => ['in', $check_id_arr]])->update($params);
                    //   echo $this->model->getLastSql();
                    if ($result !== false) {
                        $this->success();
                    }
                } catch (\think\exception\PDOException $e) {
                    $this->error($e->getMessage());
                } catch (\think\Exception $e) {
                    $this->error($e->getMessage());
                }
            }
            $this->error(__('Parameter %s can not be empty', ''));
        }
        return $this->view->fetch();
    }

    public function getPackage(){
        $new_list = [
            [
                'value'=>'筑福清洁',
                'name'=>'筑福清洁',
            ],
            [
                'value'=>'健康清洁',
                'name'=>'健康清洁',
            ],
            [
                'value'=>'幸福清洁',
                'name'=>'幸福清洁',
            ],
            [
                'value'=>'养生清洁',
                'name'=>'养生清洁',
            ]
        ];
        $this->success('', null, $new_list);
    }
    public function getDuration(){
        $new_list = [
            [
                'value'=>'单次',
                'name'=>'单次',
            ],
            [
                'value'=>'半年',
                'name'=>'半年',
            ],
            [
                'value'=>'一年',
                'name'=>'一年',
            ],
        ];
        $this->success('', null, $new_list);
    }

    public function getspecifications(){
        $new_list = [
            [
                'value'=>'630kg及以下',
                'name'=>'630kg及以下',
            ],
            [
                'value'=>'800kg',
                'name'=>'800kg',
            ],
            [
                'value'=>'1000kg',
                'name'=>'1000kg',
            ],
        ];
        $this->success('', null, $new_list);
    }

}
